package service.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/responseDemo1")
public class ResponseServlet1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*重定向方法
        * 路径：虚拟路径/responseDemo   资源路径 /responseDemo2
        * 完整路径写法： 虚拟路径+资源路径 /responseDemo/response2
        * */
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
resp.sendRedirect(contextPath+"/response2");
//        resp.sendRedirect("http://www.baidu.com");
/*请求转发路径  只有资源路径
*
*
* */
req.getRequestDispatcher("/response2").forward(req,resp);

    }
}
